package com.lock;

import org.junit.Test;

import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.locks.Lock;

public class ZKLockTest {
    @Test
    public void test() throws InterruptedException {
        AtomicInteger n = new AtomicInteger(500);
        Lock lock = new ZKLock("47.96.182.102:2181", "test1");
        for (int i = 0; i < 2; i++) {
            new Thread(() -> {
                try {
                    lock.lock();
                    System.out.println(n.decrementAndGet());
                    System.out.println(Thread.currentThread().getName() + "正在运行");
                } finally {
                    lock.unlock();
                }
            }).start();
        }
        Thread.currentThread().join();
    }
}